unit ufiltrodiario;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask;

type
  TFiltrodiario = class(TForm)
    MaskEdit1: TMaskEdit;
    Label1: TLabel;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Filtrodiario: TFiltrodiario;

implementation

uses Dados, diario, funcoes;

{$R *.dfm}

procedure TFiltrodiario.Button1Click(Sender: TObject);
var
mvalor : currency;
begin
if length(trim(maskedit1.text)) > 0  then
   begin
   if filtrodiario.Caption = 'Data' then
      begin
      mfiltro := 'where data = ' + quotedstr(maskedit1.Text);
   end;
   if filtrodiario.Caption = 'Devedora' then
      begin
      mfiltro := 'where devedora = ' + quotedstr(maskedit1.Text);
   end;
   if filtrodiario.Caption = 'Credora' then
      begin
      mfiltro := 'where credora = ' + quotedstr(maskedit1.Text);
   end;
   if filtrodiario.Caption = 'HP' then
      begin
      mfiltro := 'where hp = ' + maskedit1.Text;
   end;
   if filtrodiario.caption = 'Complemento' then
      begin
//      select * from diadbf where upper(complement) like '%RICARDO%'
      mfiltro := 'where upper(complement) like ' + quotedstr('%' + trim(maskedit1.Text) + '%');
   end;
   if filtrodiario.Caption = 'Valor' then
      begin
      mvalor         := strtofloat(maskedit1.text);
      mvalor         := mvalor / 100;
      maskedit1.Text := buscatroca(formatfloat('0.00',mvalor),',','.');
      mfiltro        := 'where valor = ' + maskedit1.text;
   end;
   close;
   exit;
end;
close;

end;

procedure TFiltrodiario.Button2Click(Sender: TObject);
begin
mfiltro := '';
close;
end;

procedure TFiltrodiario.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key=#13 then
     SelectNext(ActiveControl,true,true);
  if key=#27 then
     close;

end;

end.
